﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ThreadingApp1
{
    public class Consumer
    {
        string name;
        int time;
        Storehouse storehouse;

        public Consumer(Storehouse storehouse, string name, int time)
        {
            this.storehouse = storehouse;
            this.name = name;
            this.time = time;
        }

        public void Run()
        {
            while (true)
            {
                Console.WriteLine("Consumer " + name + " try take product from storehouse");
                string product = storehouse.ConsumeProduct();
                if (product != null)
                {
                    Console.WriteLine("Consumer " + name + " consume " + product);
                }
                else
                {
                    Console.WriteLine("There is no products in storehouse. Consumer " + name + " wait a litte bit more time");
                    Thread.Sleep(500);
                }

                Thread.Sleep(time);
            }
        }
    }
}
